define(function(require){
	var main = require('/static/main.js');
	var m = new main();
	function Cont(){
		this.Fun._init();
	}
	Cont.prototype.Fun = {
		_init:function(){
			var _this = this;
		    this.getdetial();
			this.bindEvent();
		},
        colorList:[
            '#fb4155',
            '#ff8f6e',
            '#ffe659',
            '#79c3fc',
            '#6be6c1',
            '#516b91',
            '#edafda',
            '#7a7a7a',
            '#51b7b7',
            '#338ee3',
            '#848baf',
            '#F3638B',
        ],
		getdetial:function(){
            var _this = this;
			$.ajax({
                type: "POST",
                url: "/site/get-home-data",
                dataType: "json",
                success: function (ret) {
                	if(ret.IsBizSuccess){
                        if(ret.AccountType == 100){  //datatables;
                            _this.gettables(ret.AccountBill);
                        }else{
                            var data1 = _this.getList(7,ret.SpreadCnt,ret.OrderCnt);
                            _this.getCssOne(data1);
                            _this.getTagData(ret.TagResult);

                        }
                	}else{
                		
                	}
                }
            });
		},
        getCssOne:function(data){
            var chart2 = document.getElementById('echart2');
            var echart2= echarts.init(chart2,'customed');
            var option2 = {
                color:['#00aeae','#338ee3','#717cb6'],
                tooltip: {
                    trigger: 'axis'
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data:data.dateList
                },
                yAxis: {
                    type: 'value',
                    minInterval:1
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    top: '5%',
                    bottom: '5%',
                    containLabel: true
                },
                series: [
                    {
                        name:'推广数',
                        type:'line',
                        markPoint: {
                            data: [
                                {type: 'max', name: '最大值'},
                                {type: 'min', name: '最小值'}
                            ]
                        },
                        data:data.dataList0
                    },
                    {
                        name:'订单数',
                        type:'line',
                        markPoint: {
                            data: [
                                {type: 'max', name: '最大值'},
                                {type: 'min', name: '最小值'}
                            ]
                        },
                        data:data.dataList1
                    }

                ]
            };
            echart2.setOption(option2);

        },
        getTagData:function(taglist){
            var _this = this;
            // 标签
            var data = [];
            var str = ''
            $.each(taglist,function(k,v){
                if(v.TagName == null){
                    v.TagName = '暂无标签'
                }
                var val = {
                    value : v.Count,
                    name : v.TagName,
                }
                str +='<li class="legend-item"><i class="fa fa-circle  m-r-15" style="color: '+_this.colorList[k]+'"></i>'+v.TagName+'</li>';
                $(".legend-tag").html(str);
                data.push(val);
            });
            if(data.length < 1){
                var val = {
                    value : 0,
                    name : '暂无标签'
                }
                str +='<li class="legend-item"><i class="fa fa-circle  m-r-15" style="color: '+_this.colorList[0]+'"></i>暂无标签</li>';
                $(".legend-tag").html(str);
                data.push(val);
            };
            var chart2 = document.getElementById('echart1');
            var echart2 = echarts.init(chart2,'customed');
            var option2 = {
                color:_this.colorList,
                tooltip : {
                    trigger: 'item'
                },
                legend: {
                    show:false
                },
                series : [
                    {
                        type: 'pie',
                        radius : ['50%','70%'],
                        avoidLabelOverlap: false,
                        center: ['50%', '50%'],
                        data:data,
                        label: {
                            normal: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: '20',
                                    fontWeight: 'bold'
                                }
                            }
                        },
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            echart2.setOption(option2);

        },
        getList:function(count,data,data2){
            var dateList = [];
            var dataList0 = [];
            var dataList1 = [];
            for(var i = 0; i< count; i++){
                var date = new Date(new Date()- 86400000*i );
                var Year = date.getFullYear();
                var Month = date.getMonth()+1;
                var Month1 = Month < 10 ? '0'+ Month :Month;
                var Day = date.getDate();
                Day = Day < 10 ? '0'+ Day :Day;
                dateList.splice(0, 0, Month1+'-'+Day);

                var TimeStr = Year+'-'+Month1+'-'+Day;
                var timestamp = Date.parse(TimeStr)/100000;
                var Count0 = 0;
                var Count1 = 0;

                $.each(data,function(k,v){
                    var TimeStr2 = m.formatYmd1(v.CreateTime);
                    var timestamp1 = Date.parse(TimeStr2)/100000;
                    if(timestamp == timestamp1){
                        if(typeof (data[k]) != 'undefined' && data[k].Count){
                            Count0 = data[k].Count;
                        }
                    }
                });
                $.each(data2,function(k,v){
                    var TimeStr2 = m.formatYmd1(v.CreateTime);
                    var timestamp1 = Date.parse(TimeStr2)/100000;
                    if(timestamp == timestamp1){
                        if(typeof (data2[k]) != 'undefined' && data2[k].Count){
                            Count1 = data2[k].Count;
                        }
                    }
                });
                dataList0.splice(0, 0, Count0);
                dataList1.splice(0, 0, Count1);
            }
            var JsonData = {
                dateList:dateList,
                dataList0:dataList0,
                dataList1:dataList1,
            }
           return JsonData;
        },
        gettables:function(data){
            var table = $('#datatable').dataTable({
                "searching":false,
                'bLengthChange': false,
                "bDestory": true,
                "bRetrieve": true,
                "bFilter":false,
                "bSort": false,
                "bProcessing": true,
                "autoWidth": false,
                 data:data,
                "aoColumns":[
                    {"mDataProp": 'Amount',
                        render:function(data){
                            return data > 0? '+'+data : data;
                        }
                    },
                    {"mDataProp": 'CurrentAmount'},
                    {"mDataProp": 'AccountRecType',
                        render:function(data){
                            return data == 1100 ? '销售产品收益' :'提现支出';
                        }
                    },
                    {"mDataProp": 'AccountRecStatus',
                        render:function(data){
                            var AccountRecStatus = '';
                            switch(data){
                                case 1100:AccountRecStatus = '审核中'; break;
                                case 1200:AccountRecStatus = '审核成功'; break;
                                case 1300:AccountRecStatus = '审核失败'; break;
                                case 1400:AccountRecStatus = '成功'; break;
                                case 1500:AccountRecStatus = '失败'; break;
                                case 1600:AccountRecStatus = '冻结'; break;
                                case 2000:AccountRecStatus = '成功'; break;
                            }
                            return AccountRecStatus;
                        }
                    },
                    {"mDataProp": 'Comment'},
                    {"mDataProp": 'CreateTime',
                        render:function(data){
                            return m.formatTimeAll2(data);
                        }
                    },
                ]
            }).api();
        },
		bindEvent:function(){
		}


	}
	var a = new Cont();

})